package com.shengyijie.activity.share;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
 

public class TokenStore {
	public static String fileName = "token_store";
	
	public static void store(Activity activity, int type,String token,String tokensecret) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		
		SharedPreferences.Editor editor = settings.edit();
		
		if(type==ShareConstant.SHARE_SINA){
			editor.putString("sina_token", token);
			editor.putString("sina_token_secret", tokensecret);	
		}else if(type==ShareConstant.SHARE_RENREN){
			editor.putString("renren_token", token);
			editor.putString("renren_token_secret", tokensecret);	
		}else if(type==ShareConstant.SHARE_TENCNT){
			editor.putString("tencent_token", token);
			editor.putString("tencnet_token_secret", tokensecret);	
		}
		
		
		
		editor.commit();		
	}
	
	public static String[] fetch(Activity activity,int type) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		 
		String oauth_token = null;
		String oauth_token_secret = null; 
		if(type==ShareConstant.SHARE_SINA){
			 oauth_token = settings.getString("sina_token", null);
			 oauth_token_secret = settings.getString("sina_token_secret", null); 
		}else if(type==ShareConstant.SHARE_RENREN){
			 oauth_token = settings.getString("renren_token", null);
			 oauth_token_secret = settings.getString("renren_token_secret", null);  
		}else if(type==ShareConstant.SHARE_TENCNT){
			 oauth_token = settings.getString("tencent_token", null);
			 oauth_token_secret = settings.getString("tencnet_token_secret", null); 
		}
		
		return new String[] {oauth_token, oauth_token_secret};
	}
	
	public static void clear(Activity activity,int type) {
		SharedPreferences settings = activity.getSharedPreferences(fileName, Context.MODE_PRIVATE);
		
		SharedPreferences.Editor editor = settings.edit();
		
		if(type==ShareConstant.SHARE_SINA){
			editor.putString("sina_token", null);
			editor.putString("sina_token_secret", null);	
		}else if(type==ShareConstant.SHARE_RENREN){
			editor.putString("renren_token", null);
			editor.putString("renren_token_secret", null);	
		}else if(type==ShareConstant.SHARE_TENCNT){
			editor.putString("tencent_token", null);
			editor.putString("tencnet_token_secret", null);	
		}
        editor.commit(); 
	}	
}
